/*
 * 需求：
 * 电脑主要组成部件：cpu,显卡,内存条
 * 将每个零件封装出抽象基类，并且提供不同的厂商生产不同的零件，如intel厂商和lenovo厂商
 * 创建电脑类提供让电脑工作的函数，并且调用每个零件工作的接口
 * 测试时组装三台不同的电脑进行工作 
 */
#include<iostream>
using namespace std;

class Cpu {
  public:
    virtual void calculate() = 0;
};

class VideoCard {
  public:
    virtual void display() = 0;
};

class Memory {
  public:
    virtual void storage() = 0;
};

class Computer {
  public:
    Computer(Cpu *cpu, VideoCard *videoCard, Memory *memory) {
      m_cpu = cpu;
      m_videoCard = videoCard;
      m_memory = memory;
    }
    ~Computer() {
      if (m_cpu != NULL) {
        delete m_cpu;
        m_cpu = NULL;
      }
      if (m_videoCard != NULL) {
        delete m_videoCard;
        m_videoCard = NULL;
      }
      if (m_memory != NULL) {
        delete m_memory;
        m_memory = NULL;
      }
      
    }
    void work() {
      cout<< "computer work" <<endl;
      m_cpu->calculate();
      m_videoCard->display();
      m_memory->storage();
    }
  private:
    Cpu *m_cpu;
    VideoCard *m_videoCard;
    Memory *m_memory;
};

// intel的零件
class IntelCpu: public Cpu{
  public:
    void calculate() {
      cout << "interCpu calculate" <<endl;
    }
};

class IntelVideoCard: public VideoCard{
  public:
    void display() {
      cout << "InterVideoCard display" <<endl;
    }
};

class IntelMemory: public Memory{
  public:
    void storage() {
      cout << "InterMemory storage" <<endl;
    }
};

// 联想的零件
class LenovoCpu: public Cpu{
  public:
    void calculate() {
      cout << "LenovoCpu calculate" <<endl;
    }
};

class LenovoVideoCard: public VideoCard{
  public:
    void display() {
      cout << "LenovoVideoCard display" <<endl;
    }
};

class LenovoMemory: public Memory{
  public:
    void storage() {
      cout << "LenovoMemory storage" <<endl;
    }
};

void test0() {
  Cpu *intelCpu = new IntelCpu;
  VideoCard *intelVideoCard = new IntelVideoCard;
  Memory *intelMemory = new IntelMemory;
  Computer *computer1 = new Computer(intelCpu, intelVideoCard, intelMemory);
  computer1->work();
  delete computer1;
};

void test1() {
  Cpu *lenovoCpu = new LenovoCpu;
  VideoCard *lenovoVideoCard = new LenovoVideoCard;
  Memory *lenovoMemory = new LenovoMemory;
  Computer *computer2 = new Computer(lenovoCpu, lenovoVideoCard, lenovoMemory);
  computer2->work();
  delete computer2;
};

int main() {
  test0();
  return 0;
};
 
